package com.zuimei.zuimei.utils;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.zuimei.zuimei.R;

/**
 * Created by Jogger on 2017/1/19.
 * 沉浸状态栏工具
 */

public class StatusUtil {
    private boolean isOpenStatus = true;

    public boolean isOpenStatus() {
        return isOpenStatus;
    }

    public void setOpenStatus(boolean openStatus) {
        isOpenStatus = openStatus;
    }

    public void openStatusActivity(Activity activity) {
        //沉浸式状态栏（透明状态栏） -- android4.4以后提供
        Window window = activity.getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //5.0以上
            window.getDecorView().setSystemUiVisibility(View
                    .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);//让子控件填充整个屏幕
            window.setStatusBarColor(Color.parseColor("#3f000000"));//把状态栏设置为透明
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //4.4以上
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        //找到指定的控件，设置paddingtop为状态栏的高度（如果找到一个id为actionbar的控件，则对它他设置paddingtop为状态栏的高度）
        View view = activity.findViewById(R.id.actionbar);
        if (view != null) {
            int statusHeight = ScreenUtil.getStatusHeight(activity);
            if (statusHeight != -1) {
                view.setPadding(0, statusHeight, 0, 0);
            }
        }
    }

}
